#!/bin/bash

ICON='🌐'

# Interface
wired_interface=$(ip -o link show | awk -F': ' '{print $2}' | grep "^e" | head -n 1)
wireless_interface='wlan0'

# Wireless network
if [[ -d "/sys/class/net/${wireless_interface}" ]]; then
    wireless_ip_addr=$(ip addr show dev "${wireless_interface}" | awk '/inet / {print $2}' | cut -d'/' -f1)
    if [[ -n "${wireless_ip_addr}" ]]; then
        ip_addr="${wireless_ip_addr}"
        ICON='📶'
    fi
fi

# Wired network
if [[ -d "/sys/class/net/${wired_interface}" ]]; then
    wired_ip_addr=$(ip addr show dev "${wired_interface}" | awk '/inet / {print $2}' | cut -d'/' -f1)
    if [[ -n "${wired_ip_addr}" ]]; then
        ip_addr="${wired_ip_addr}"
    fi
fi

printf "${ICON} %s│" "${ip_addr}"

# EOF

